﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.QueryModel;
using XbsWebAPI.Application.RoomStatus.Dtos;

namespace XbsWebAPI.MainHost.Controllers
{
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class RoomStatusController : Controller
    {
        private readonly IRoomStatusAppService _roomStatusAppService;
        public RoomStatusController(IRoomStatusAppService roomStatusAppService)
        {
            _roomStatusAppService = roomStatusAppService;
        }

        /// <summary>
        /// 下拉框 展示房型列表
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<SelectHouseTypeDto>> FindSelectHouseTypes()
        {
            return _roomStatusAppService.GetSelectHouseTypes();
        }

        /// <summary>
        /// 房态的筛选条件，按条件显示总的房间状态以及对应房间的数量
        /// </summary>
        /// <param name="useDate">房态日期，不输入默认查询当天的时间</param>
        /// <param name="campId">营位Id，不输入默认全查</param>
        /// <param name="houseTypeId">房型Id，不输入默认全查</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<RoomStatusFilterDto>> FindSelectRoomStatusFilters(DateTime? useDate, Guid? campId, Guid? houseTypeId)
        {
            return _roomStatusAppService.GetSelectRoomStatusFilters(useDate, campId, houseTypeId);
        }

        /// <summary>
        /// 房态管理页面，展示所有的房间并对应状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<RoomStatusSignDto>> FindRoomStatusPagedList([FromQuery]QueryRoomStatus query)
        {
            var result = _roomStatusAppService.GetRoomStatusSigns(query);

            return result;
        }

        /// <summary>
        /// 可退房的房间详情
        /// </summary>
        /// <param name="orderId">订单Id</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<RoomStatusCheckOutDetaiDto> FindCheckOutRoomDetail(Guid orderId)
        {
            ResultDto<RoomStatusCheckOutDetaiDto> result = _roomStatusAppService.GetCheckOutRoomDetail(orderId);

            return result;
        }


        /// <summary>
        /// 取消预订
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public async Task<ResultDto<string>> CancelBookingOrder(Guid orderId)
        {
            var result = await _roomStatusAppService.CancelBookingOrder(orderId);

            return result;
        }
    }
}
